package com.gxa.controller.SystemController;

import com.gxa.entity.Admin;
import com.gxa.entity.Notice;
import com.gxa.service.system.NoticeService;
import com.gxa.utils.R;
import com.gxa.vo.NoticeVo;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Api(tags = "消息公告管理模块")
@RestController
public class NoticeController {

    @Autowired
    private NoticeService noticeService;


    @ApiOperation(value="Notice列表接口",notes="查询全部消息公告信息",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回所有的消息公告详细信息",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("sys:sel")
    @GetMapping("/notice/qureyAllNotice")
    public R queryAllNotice(){
        List<NoticeVo> noticeVos = noticeService.queryAllNotice();
        return R.ok().put("data",noticeVos);
    }

    @ApiOperation(value="Notice查询接口",notes="根据输入内容查询消息公告信息",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回所有的消息公告详细信息",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("sys:sel")
    @PostMapping("/notice/qureyNotices")
    public R queryNotices(@ApiParam(name="notice",value = "消息公告标题参数--这里输入要查询的消息公告标题",required = true)@RequestBody NoticeVo notice){
        System.out.println(notice.getTitle());
        List<NoticeVo> noticeVos = noticeService.queryNoticeByTitle("%"+notice.getTitle()+"%");
        return R.ok().put("data",noticeVos);
    }

    @ApiOperation(value="Notice增加接口",notes="增加消息公告接口",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回增加是否成功",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("sys:add")
    @PostMapping("/notice/addNotice")
    public R addNotice(@ApiParam(name="notice",value = "消息公告参数--这里写输入的消息公告信息描述",required = true)@RequestBody NoticeVo notice){
        System.out.println(notice);
        noticeService.addNotice(notice);
        return R.ok();
    }

    @ApiOperation(value="进入编辑Notice接口",notes="进入操作列编辑消息公告操作接口",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "根据消息公告id查询到的消息公告详细信息",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("sys:sel")
    @PostMapping("/notice/preEditNotice")
    public R preEditNotice(@ApiParam(name="notice",value = "消息公告id",required = true)@RequestBody NoticeVo notice){
        System.out.println(notice.getId());
        NoticeVo noticeVo = noticeService.selNoticeById(notice.getId());
        return R.ok().put("data",noticeVo);
    }

    @ApiOperation(value="编辑Notice接口",notes="编辑消息公告操作接口",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回编辑是否成功",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("sys:update")
    @PutMapping("/notice/editNotice")
    public R editNotice(@ApiParam(name="notice",value = "消息公告参数--这里写输入的消息公告信息描述",required = true)@RequestBody NoticeVo notice){
        System.out.println(notice);
        noticeService.updateNotice(notice);
        return R.ok();
    }

    @ApiOperation(value="删除Notice接口",notes="删除消息公告操作接口",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回删除是否成功",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("sys:del")
    @DeleteMapping("/notice/delNotice")
    public R delNotice(@ApiParam(name="notice",value = "消息公告id",required = true)@RequestBody NoticeVo noticeVo){
        System.out.println(noticeVo.getId());
        noticeService.delNotice(noticeVo.getId());
        return R.ok();
    }
}
